﻿using Framework.EncryptionDecryptionService.Enums;
using Framework.EncryptionDecryptionService.Helpers;
using Framework.EncryptionDecryptionService.Inteface;
using Framework.EncryptionDecryptionService.Models;

namespace Framework.EncryptionDecryptionService.Abstract
{
    /// <summary>
    /// 加密服务抽象类
    /// </summary>
    public abstract class AbsEncryptionService : IEncryptionService
    {
        /// <summary>
        /// 秘钥
        /// </summary>
        internal readonly ISecretKeyService SecretKey;

        public SecretKeyModel GetSecretKey  { get { return new SecretKeyModel(SecretKey?.PrivateSecretKey, SecretKey?.PublicSecretKey); } }

        /// <summary>
        /// 加密服务抽象类
        /// </summary>
        /// <param name="secretKey">秘钥</param>
        public AbsEncryptionService(ISecretKeyService secretKey)
        {
            SecretKey = secretKey;
        }
        public abstract byte[] Encrypt(string data);

        public virtual string Encrypt<T>(T data) where T : class, new()
        {
            byte[] byte_ = Encrypt(data.ConvertToString());
            return byte_.ToBase64String();
        }
    }
}
